package com.rmfyzxfw.caseprocess.model.dynamic.query;

import com.google.common.collect.Lists;
import com.rmfyzxfw.caseprocess.enums.SortEnum;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.util.List;

/**
 * @author long@flyfox
 */
@Data
public class SortCondition {

    private static List<String> defaultOrderFields = Lists.newArrayList("id");

    /**
     * 排序字段
     */
    private List<String> orderFields;

    /**
     * 排序规则 默认降序
     */
    private SortEnum sortEnum;


    private SortCondition() {
    }

    public SortCondition(List<String> orderFields, SortEnum sortEnum) {
        this.orderFields = orderFields;
        this.sortEnum = sortEnum;
    }

    public SortCondition(List<String> orderFields) {
        this.orderFields = orderFields;
    }

    public String getDirection() {
        if (sortEnum == null) {
            return SortEnum.DESC.name();
        }
        return sortEnum.name();
    }

    public List<String> getOrderFields() {
        if (CollectionUtils.isEmpty(orderFields)) {
            return defaultOrderFields;
        }
        return orderFields;
    }
}
